package com.shinewind.payment.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shinewind.payment.mapper.IRelateGoodsMapper;
import com.shinewind.payment.service.IRelateGoodsService;
import com.shinewind.pojo.entity.RelateGoods;
import com.shinewind.pojo.vo.CartVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class RelateGoodsServiceImpl extends ServiceImpl<IRelateGoodsMapper, RelateGoods> implements IRelateGoodsService {
    @Override
    public Boolean saveByListANDOrderId(String orderId, List<CartVo> goodsList) {
        List<RelateGoods> relateGoodsList = goodsList.stream().map(good ->{
            RelateGoods relateGoods = RelateGoods.builder().build();
            BeanUtils.copyProperties(good,relateGoods);
            relateGoods.setOrderId(orderId);
            return relateGoods;
        }).collect(Collectors.toList());
        if(relateGoodsList.size() > 0){
            return this.saveBatch(relateGoodsList) == true ? true : false;
        }
        else{
            return false;
        }
    }
}
